public class Singleton2 {
    //单例模式：懒汉模式

    private Singleton2(){
        System.out.println(Thread.currentThread().getName()+"");
    }
    private static Singleton2 singleton2; //类加载时还没实例化

    public static Singleton2 getInstance(){

        if(singleton2 == null){
            singleton2=new Singleton2();
        }
        return singleton2;
    }
    public static void main(String[] args) {

        for(int i=0;i<5;i++){
   //lambda表达式创建匿名类对象
            new Thread(()->{
                Singleton2.getInstance();
            }).start();
        }
    }
}
